package webapp;

import javax.jws.WebService;

import webapp.lib.CustomException;
import webapp.lib.ObjectFactory;
import webapp.lib.Request;
import webapp.lib.Response;
import webapp.lib.ElfProef;
import webapp.lib.WSInterface;

@WebService( endpointInterface = "webapp.lib.WSInterface") //Controlleren of dit klopt
public class CoVImpl implements WSInterface {

	public Response checkCoV(Request request) {
		
		ElfProef ep = new ElfProef();
		ObjectFactory factory = new ObjectFactory();
		Response response = factory.createResponse();
		boolean isGeldig = false;
		
		try {
			if(ep.check(request.getBSN()) && request.getPolis().matches("[0-9]{1,15}") && request.getUzovi().matches("[0-9]{4}")) {
				isGeldig = true;
			} else {
				response.setFoutmelding("Het Uzovi en/of polis nummer is niet goed,");
			}
		} catch(CustomException e) {
			// foutmelding doorsturen e.getMessage()
			response.setFoutmelding(e.getMessage());
		} catch(RuntimeException e) {
			// Error handling
			response.setFoutmelding(e.getMessage());
		}
		response.setResult(isGeldig);
		return response;
	}
	
}
